import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:photo_view/photo_view_gallery.dart';

class HeroPage extends StatefulWidget {
  const HeroPage({super.key});

  @override
  State<HeroPage> createState() => _HeroPageState();
}

class _HeroPageState extends State<HeroPage> {
  late List listData;
  late int initialPage;
  late int currentPage;
  late final arguments;

  @override
  void initState() {
    super.initState();
    arguments = Get.arguments;
    listData = arguments["listData"];
    initialPage = arguments["initialPage"];
    currentPage = initialPage + 1;
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Navigator.pop(context);
      },
      child: Hero(
        tag: arguments["imageUrl"],
        child: Stack(
          children: [
            Scaffold(
              body: Center(
                child: PhotoViewGallery.builder(
                    itemCount: listData.length,
                    pageController: PageController(initialPage: initialPage),
                    onPageChanged: (index) {
                      if (kDebugMode) {
                        print(index);
                      }
                      setState(() {
                        currentPage = index + 1;
                      });
                    },
                    builder: (context, index) {
                      return PhotoViewGalleryPageOptions(
                          imageProvider:
                              NetworkImage(listData[index]["imageUrl"]));
                    }),
              ),
            ),
            Positioned(
              bottom: 40,
              left: 0,
              right: 0,
              child: Container(
                alignment: Alignment.center,
                child: Text(
                  "${currentPage}/${listData.length}",
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 18,
                    decoration: TextDecoration.none,
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
